<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/9/16
  Time: 11:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>首页--汽车租赁系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/public.css" media="all" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui_ext/dtree/dtree.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui_ext/dtree/font/dtreefont.css">
</head>
<body class="childrenBody">
<!-- 搜索条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查询条件</legend>
</fieldset>
<form class="layui-form" method="post" id="searchFrm">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">出租单号:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="rentid" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入出租单号" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">身份证号:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="identity" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入身份证号" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">车牌号:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="carnumber" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入车牌号" style="height: 30px;border-radius: 10px">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">开始时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="startTime" id="startTime" readonly="readonly"
                       class="layui-input layui-input-inline"
                       placeholder="请输入出租开始时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">结束时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="endTime" id="endTime" readonly="readonly"
                       class="layui-input layui-input-inline"
                       placeholder="请输入出租结束时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">出租单状态:</label>
            <div class="layui-input-inline">
                <input type="radio" name="rentflag" value="0" title="未归还">
                <input type="radio" name="rentflag" value="1" title="已归还">
            </div>
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center">
        <div class="layui-input-black" >
            <button type="button"
                    class="layui-btn layui-btn-normal layui-icon layui-icon-search layui-btn-radius layui-btn-sm"
                    lay-submit  lay-filter="doSearch" style="margin-top: 4px">查询
            </button>
            <button type="reset"
                    class="layui-btn layui-btn-warm layui-icon layui-icon-refresh layui-btn-radius layui-btn-sm"
                    style="margin-top: 4px">重置
            </button>
        </div>
    </div>

</form>
<!-- 搜索条件结束 -->
<table id="rentTable" lay-filter="rentTable"></table>


<script id="barCar" type="text/html">

    <%-- 汽车未归还显示编辑和删除按钮， 如果归还就不显示 --%>
    {{#  if(d.rentflag == 0){ }}
    <a class="layui-btn layui-btn-xs layui-btn-radius" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-radius" lay-event="del">删除</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-green layui-btn-xs layui-btn-radius" lay-event="exportRent">导出出租单</a>
    {{# } }}

</script>



<!-- 添加和修改的弹出层-->
<div style="display: none;padding: 20px" id="saveOrUpdateDiv">
    <form class="layui-form" lay-filter="dataFrm" id="dataFrm">
        <div class="layui-form-item">
            <label class="layui-form-label">出租单号:</label>
            <div class="layui-input-block">
                <input type="text" name="rentid" lay-verify="required" readonly="readonly" placeholder="请输入出租单号"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">起租时间:</label>
                <div class="layui-input-inline">
                    <input type="text" name="begindate" id="begindate" readonly="readonly" lay-verify="required" placeholder="请输入起租时间" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">还车时间:</label>
                <div class="layui-input-inline">
                    <input type="text" name="returndate" id="returndate" readonly="readonly"  placeholder="请输入还车时间" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">身份证号:</label>
                <div class="layui-input-inline">
                    <input type="text" name="identity" lay-verify="required" readonly="readonly" placeholder="请输入身份证号"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">车牌号:</label>
                <div class="layui-input-inline">
                    <input type="text" name="carnumber" lay-verify="required" readonly="readonly"  placeholder="请输入车牌号" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">出租价格:</label>
                <div class="layui-input-inline">
                    <input type="text" name="price" lay-verify="required" placeholder="请输入出租价格" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">操作员:</label>
                <div class="layui-input-inline">
                    <input type="text" name="openname" id="openname" lay-verify="required" placeholder="请输入操作员" readonly="readonly" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;padding-right: 120px">
                <button type="button"
                        class="layui-btn layui-btn-normal layui-btn-md layui-icon layui-icon-release layui-btn-radius"
                        lay-filter="doSubmit" lay-submit="">提交
                </button>
                <button type="reset"
                        class="layui-btn layui-btn-warm layui-btn-md layui-icon layui-icon-refresh layui-btn-radius">重置
                </button>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/index.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/cache.js"></script>
<script>
    var tab;
    layui.use(
        ['table', 'layer', 'form', 'jquery','upload','laydate'], function () {
            var table = layui.table;
            var form = layui.form;
            var $ = layui.jquery;
            var layer = layui.layer;
            var upload=layui.upload;
            var laydate = layui.laydate;

            laydate.render({
                elem: '#startTime' //指定元素
                , type: "datetime"
            });

            laydate.render({
                elem: '#endTime' //指定元素
                , type: "datetime"
            });

            tab = table.render({
                elem: '#rentTable',
                url: "${pageContext.request.contextPath}/carRentInfo/carRentInfoShow",
                cellMinWidth: 30,
                page: {limit: 5, limits: [5, 10, 15, 20]},
                toolbar: '#toolbarCar',//开启头部工具栏，并为其绑定左侧模板
                cols: [[
                    {field: 'rentid', width: 150, title: '出租单号', sort: true}
                    ,{field: 'identity', width: 80, title: '身份证号', sort: true}
                    , {field: 'carnumber', width: 80, title: '车牌号', sort: true}
                    , {field: 'price', width: 80, title: '出租价格'}
                    ,{field: 'rentflag', width: 110, title: '归还状态', sort: true,templet: function (data) {
                             return data.rentflag == 0 ? '<span style="color:red;">未归还</span>': '已归还'}}
                    ,{field: 'begindate', width: 80, title: '起租时间', sort: true}
                    ,{field: 'returndate', width: 80, title: '归还时间', sort: true}
                    ,{field: 'openname', width: 80, title: '操作员', sort: true}
                    ,{field: 'createtime', width: 120, title: '录入时间', sort: true}
                    , {fixed: 'right', title: '操作', toolbar: '#barCar'}
                ]]
            })

            form.on('submit(doSearch)', function (data) {
                //ajax数据
                tab.reload({
                    where: data.field
                })
                //不跳转页面
                return false;
            })

            table.on('tool(rentTable)', function (obj) {
                var data = obj.data
                if (obj.event == "edit") { // 编辑
                    rentInfoUpdate(data)
                }else if(obj.event=="exportRent"){
                    //导出
                    exportRent(data)
                }
            })
var index;
            function rentInfoUpdate(data) {
                index = layer.open({
                    type: 1,
                    title: '修改车辆',
                    content: $("#saveOrUpdateDiv"),
                    area: ['800px', '440px'],
                    success: function () {
                        // 给form表单设置值
                        // 把当前行的数据data显示到form表单中去,form表单中是有id隐藏字段
                        form.val("dataFrm", data)
                    }
                })
            }
            form.on('submit(doSubmit)', function (data) {
                var param = $("#dataFrm").serialize()
                layer.confirm("确定要提交该数据么", function (r) {
                    $.get("${pageContext.request.contextPath}/carRentInfo/rentInfoUpdate?" + param, function (rr) {
                        layer.msg(rr.msg)
                        layer.close(index)
                        tab.reload()
                    })
                })
                return false;
            })

            function exportRent(data){
                location.href="${pageContext.request.contextPath}/carRentInfo/exportRentInfo?rentid="+data.rentid
            }


        })

</script>
</body>
</html>
